import 'package:flutter/material.dart';

//导航参数的传递和接收

//1、声明数据结构类
class Car {
  String brand;
  String color;

  Car(this.brand, this.color);
}

//2、实现CarDetail组件
class CarDetailWidget extends StatelessWidget {
  Car car;

  CarDetailWidget({@required this.car,Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(car.brand),
      ),
      body: Center(
        child: Text(car.color),
      ),
    );
  }
}

//3、实现CarList组件
class CarListWidget extends StatelessWidget {
  List<Car> carList = [Car("劳斯莱斯", "金黄色"), Car("兰博基尼", "大红色")];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("CarListWidget"),
      ),
      body: Center(
        child: ListView.builder(
            itemCount: carList.length,
            itemBuilder: (context, index) {
              return ListTile(
                title: Text(carList[index].brand),
                subtitle: Text(carList[index].color),
                onTap: () {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) =>
                              CarDetailWidget(car:carList[index])));
                },
              );
            }),
      ),
    );
  }
}
